package com.chase.passwordmaster.entity

import com.chase.passwordmaster.encoder.decoded
import com.chase.passwordmaster.encoder.encoded
import org.litepal.crud.LitePalSupport

/**
 * You are supposed to guarantee that all
 * instances of Account has been encrypted
 */

open class Account(
    var website: String,
    var username: String,
    var password: String,
    var name: String? = null,
    var tel: String? = null,
    var qq: String? = null,
    var weChat: String? = null,
    var email: String? = null,
    var memo: String? = null,
    var id: Long? = null
) : LitePalSupport() {

    constructor(): this(
        "website",
        "username",
        "password",
        null,
        null,
        null,
        null,
        null,
        null,
        null
    )

//    fun encode() {
//        username = username.encoded()
//        password = password.encoded()
//        tel = tel?.encoded()
//        qq = qq?.encoded()
//        weChat = weChat?.encoded()
//        email = email?.encoded()
//    }
//
//    @Deprecated(
//        "这样会修改Account，规定是数据库中存储加密对象，直接对Account解密而保存时忘记加密存在潜在风险，如果只是用于获取解密信息建议使用getDecoded()，返回解密后的新实例而不修改原实例",
//        replaceWith = ReplaceWith("getDecoded()")
//    )
//    fun decode() {
//        username = username.decoded()
//        password = password.decoded()
//        tel = tel?.decoded()
//        qq = qq?.decoded()
//        weChat = weChat?.decoded()
//        email = email?.decoded()
//    }
//
//    fun getDecoded() = Account(
//        website = website,
//        username = username.decoded(),
//        password = password.decoded(),
//        name = name,
//        tel = tel?.decoded(),
//        qq = qq?.decoded(),
//        weChat = weChat?.decoded(),
//        email = email?.decoded(),
//        memo = memo,
//        id = id
//    )
//
//    fun getDecryptedWebsite() = website
//    fun getDecryptedUsername() = username.decoded()
//    fun getDecyptedPassword() = password.decoded()
//    fun getDecyptedName() = name
//    fun getDecyptedTel() = tel?.decoded()
//    fun getDecyptedQQ() = qq?.decoded()
//    fun getDecyptedWeChat() = weChat?.decoded()
//    fun getDecyptedEmail() = email?.decoded()
//    fun getDecyptedMemo() = memo
}